package edu.neusoft.yuejian_09.model;

import java.util.List;

import edu.neusoft.yuejian_09.base.Constant;
import edu.neusoft.yuejian_09.base.RetrofitBaseModel;
import edu.neusoft.yuejian_09.base.RetrofitListener;
import edu.neusoft.yuejian_09.bean.Activities;
import edu.neusoft.yuejian_09.bean.ActivityOrder;
import edu.neusoft.yuejian_09.service.ActivityService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import android.provider.SyncStateContract;

/**
 * Created by 爽 on 2017/9/27.
 */

public class ActivityModel extends RetrofitBaseModel {

    public ActivityService activityService;
    public ActivityModel(){
        this.activityService=retrofit.create(ActivityService.class);
    }
    private int flag;


    //获取活动列表
    public void astivitylist( final RetrofitListener listener){
        ActivityService activityService=retrofit.create(ActivityService.class);
        Call call=activityService.getAllActivities();
        Callback<List<Activities>> callback=new Callback<List<Activities>>(){
            @Override
            public void onResponse(Call<List<Activities>> call, Response<List<Activities>> response ){
                List<Activities> data=response.body();
                listener.onSuccess(data,flag);
            }
            @Override
            public  void onFailure(Call<List<Activities>> call,Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    //获取活动详情
    public void getActivityById(int Activity_id, final RetrofitListener listener){
        Call call=activityService.getActivityById(Activity_id);
        bindCallback(call,listener, Constant.ACTIVITYBYID);
    }

    //搜索活动
    public void getActBySearch(String SearchKey, final RetrofitListener listener){
        ActivityService activityService=retrofit.create(ActivityService.class);
        Call call=activityService.getActBySearch(SearchKey);
        Callback<List<Activities>> callback=new Callback<List<Activities>>(){
            @Override
            public void onResponse(Call<List<Activities>> call, Response<List<Activities>> response ){
                List<Activities> data=response.body();
                listener.onSuccess(data,flag);
            }
            @Override
            public  void onFailure(Call<List<Activities>> call, Throwable t){
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    //活动报名
    public void insertOrder(int user_id,int activity_id, final RetrofitListener listener){
        Call call=activityService.insertOrder(user_id,activity_id);
        bindCallback(call,listener, Constant.ACTIVITY);
    }
}
